/*
    Speedbump aka Project Kimbula
    Copyright (C) 2010  Ping Shin Ching

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see http://www.gnu.org/licenses.

	Ping Shin Ching
	righteous.ninja@gmail.com OR ping_sc@hotmail.com
	More information at http://www.tidytutorials.com/p/speedbump.html
 */


#ifndef protocolhttphandler_h
#define protocolhttphandler_h

#include "xsocket.h"
//#include "httphandler.h"
#include "capinterface.h"
#include "interfaces/protocolhandlerinterface.h"

#define BUFFER_SIZE	2048
#define BUFFER_SIZE2	2048

class HTTPHandler;

struct ProtocolHTTPParams{
	int proxyport;
	char* proxyaddress;
	int inactivetimeout;
	int fullforward;
	CAPInterface* capi;
	void* capi_param1;
};

class ProtocolHTTPHandler: public ProtocolHandlerInterface{
public:	
	void* Run(ProtocolHandlerParams*);
	~ProtocolHTTPHandler();
private:
	enum PCORE_NEXTPROCESS{
		PCORE_REMOTE_CONNECTING, 
		PCORE_REMOTE_RECONNECTING, 
		PCORE_REMOTE_CONNECTED,
		PCORE_REMOTE_SSL_CONNECTING,
		PCORE_REMOTE_DIRECT_CONNECT,
		PCORE_QUIT
	}; 

	int OpenConnectionToHost(int*, const char*, const int);
	void ShortCircuit(int*, int*, fd_set*, fd_set*, fd_set*, HTTPHandler*, const char*);
};

/*
 * This is the HTTP Handler Factory 
 */
class ProtocolHTTPHandlerFactory: public ProtocolHandlerFactoryInterface{
private:
	ProtocolHTTPParams* param1;
	CAPInterface* capi;

public:
        short CheckProtocol(const char*, const unsigned int);
        ProtocolHandlerFunction GetFunction();
        ProtocolHandlerInterface* GetHandler();
        const char* GetProtocolName();
	~ProtocolHTTPHandlerFactory();
	ProtocolHTTPHandlerFactory();
        void* InitProtocolFactoyHanlder(InitInterface*);
};

#endif
